import request from "@/utils/request";
// 属性值类型
export interface attrValueItemType {
  id?: number;
  valueName: string;
  attrId: number | undefined;
  isEdit?: boolean;
}

// 属性值列表类型
export type attrValueListType = attrValueItemType[];

// 全部属性类型
export interface attrItemType {
  id?: number;
  //当前平台属性的名字
  attrName: string;
  categoryId: number;
  categoryLevel: number;
  //当前属性的属性值列表
  attrValueList: attrValueListType;
  selectData?: string;//用来收集选中
}

// 全部属性列表类型
export type attrListType = attrItemType[];

// 根据三级分类请求当前分类属性列表
export const reqAttrInfoList = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return request.get<null, attrListType>(
    `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
  );
};

// 提交新增属性或者修改属性
export const reqAddOrUpdateAttrList = (newAttr: attrItemType) => {
  return request.post(`/admin/product/saveAttrInfo`, newAttr);
};

// 删除某个属性的请求
export const reqDelAttr = (id: number) => {
  return request.delete(`/admin/product/deleteAttr/${id}`);
};
